/*
使用方法：
var mb=new MessageBar("mb");
mb.showMsg("Hello!");
*/

function MessageBar(name)
{
	this.name=name;
	this.div=null;  //显示信息的DIV对象
	this.text=null;  //显示的文字对象
	this.handle=null;  //如果设置了时间调用，这里存放句柄
	this.opacity=100;  //当前的透明度

	{
		this.div=document.createElement("DIV");
		this.div.style.position="absolute";
		this.div.style.fontSize="12px";
		this.div.style.backgroundColor="#FFCCFF";
		this.div.style.display="none";
		this.div.style.padding="2 10 2 10";

		document.body.appendChild(this.div);
		onscrollEvents.push(this.name+".move();");
		onresizeEvents.push(this.name+".move();");
	}

	/*
	当页面滚动时，要调用此方法以将信息栏重新定位。  */
	this.move=function method()
	{
		if(IE)
		{
			this.div.style.top=document.body.scrollTop+document.body.clientHeight-20;
			this.div.style.left=0;
			//this.div.style.width=document.body.clientWidth;
		}
		else
		{
			this.div.style.top=self.pageYOffset+document.body.clientHeight-20;
			this.div.style.left=0;
			//this.div.style.width=document.body.clientWidth;
		}
	}

	/*
	显示一条信息  */
	this.showMsg=function method(msg,autoHide)
	{
		if(autoHide==null) autoHide=true;  //如果不设定是否自动隐藏，默认隐藏
		
		if(this.text!=null)
			this.div.removeChild(this.text);
		
		this.text=document.createTextNode(msg);
		this.div.appendChild(this.text);

		if(this.div.style.display=="none")
			this.div.style.display="";

		this.move();

		if(this.handle!=null) clearTimeout(this.handle);
		if(autoHide) this.handle=setTimeout(this.name+".hide();",2000);

		this.opacity=100;
		this._setOpacity();
	}
	
	this.showInfo=function method(msg,autoHide)
	{
		this.div.style.backgroundColor="#FFCC00";
		this.showMsg(msg,autoHide);
	}
	
	this.showResult=function method(msg,autoHide)
	{
		this.div.style.backgroundColor="#33FF00";
		this.showMsg(msg,autoHide);	
	}
	
	this.showError=function method(msg,autoHide)
	{
		this.div.style.backgroundColor="#FF0000";
		this.showMsg(msg,autoHide);		
	}

	this.hide=function method()
	{
		this.opacity-=10;
		this._setOpacity();


		if(this.opacity>0)
			this.handle=setTimeout(this.name+".hide();",300);
		else
		{
			this.handle=null;

			if(this.text!=null)
			{
				this.div.removeChild(this.text);
				this.text=null;
			}

			this.div.style.display="none";
		}
	}

	this._setOpacity=function method()
	{
		if(IE)
			this.div.style.filter="alpha(opacity="+this.opacity+")";
		else
			this.div.style.opacity=this.opacity/100;
	}
}

//添加信息条
var MB;
onloadEvents.push("MB=new MessageBar('MB');");